home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bawk.zip / BAWK.H < prev    next >
Text File  |  1986-04-15  |  6KB  |  224 lines

  1. /*
  2.  * Bawk constants and variable declarations.
  3.  */
  4. #ifdef BDS_C
  5. #define EXTERN /* */
  6. #else
  7.  
  8. #ifdef MAIN
  9. #define EXTERN /* */
  10. #else
  11. #define EXTERN extern
  12. #endif
  13.  
  14. #endif
  15.  
  16.  
  17. #define DEBUG 1    /* remove this line to compile without debug statements */
  18. #ifdef DEBUG
  19. EXTERN char Debug;        /* debug print flag */
  20. #endif
  21.  
  22. /*
  23.  * Table and buffer sizes
  24.  */
  25. #define MAXLINELEN    128    /* longest input line */
  26. #define MAXWORDS    (MAXLINELEN/2)    /* max # of words in a line */
  27. #define MAXWORKBUFLEN    4096    /* longest action or regular expression */
  28. #define MAXVARTABSZ    50    /* max # of symbols */
  29. #define MAXVARLEN    10    /* symbol name length */
  30. #define MAXSTACKSZ    40    /* max value stack length (for expressions) */
  31.  
  32.  
  33. /**********************************************************
  34.  * Current Input File variables                           *
  35.  **********************************************************/
  36. /*
  37.  * Current Input File pointer:
  38.  */
  39. #ifdef BDS_C
  40. EXTERN char *Fileptr, Curfbuf[ BUFSIZ ];
  41. #else
  42. EXTERN FILE *Fileptr;
  43. #endif
  44. EXTERN char *Filename;        /* current input file name */
  45. EXTERN int Linecount;        /* current input line number */
  46. EXTERN int Recordcount;        /* record count */
  47. /*
  48.  * Working buffers.
  49.  */
  50. EXTERN char Linebuf[ MAXLINELEN ];    /* current input line buffer */
  51. EXTERN char *Fields[ MAXWORDS ];        /* pointers to the words in Linebuf */
  52. EXTERN int Fieldcount;            /* and the # of words */
  53. EXTERN char Workbuf[ MAXWORKBUFLEN ];    /* work area for C action and */
  54.                     /* regular expression parsers */
  55.  
  56. /**********************************************************
  57.  * Regular Expression Parser variables                    *
  58.  **********************************************************/
  59. /*
  60.  * Tokens:
  61.  */
  62. #define CHAR    1
  63. #define BOL    2
  64. #define EOL    3
  65. #define ANY    4
  66. #define CLASS    5
  67. #define NCLASS    6
  68. #define STAR    7
  69. #define PLUS    8
  70. #define MINUS    9
  71. #define ALPHA    10
  72. #define DIGIT    11
  73. #define NALPHA    12
  74. #define PUNCT    13
  75. #define RANGE    14
  76. #define ENDPAT    15
  77.  
  78.  
  79. /**********************************************************
  80.  * C Actions Interpreter variables                        *
  81.  **********************************************************/
  82. /*
  83.  * Tokens:
  84.  */
  85. #define T_STRING    'S'    /* primaries: */
  86. #define T_DOLLAR    '$'
  87. #define T_REGEXP    'r'
  88. #define T_CONSTANT    'C'
  89. #define T_VARIABLE    'V'
  90. #define T_FUNCTION    'F'
  91. #define T_SEMICOLON    ';'    /* punctuation */
  92. #define T_EOF        'Z'
  93. #define T_LBRACE    '{'
  94. #define T_RBRACE    '}'
  95. #define T_LPAREN    '('
  96. #define T_RPAREN    ')'
  97. #define T_LBRACKET    '['
  98. #define T_RBRACKET    ']'
  99. #define T_COMMA        ','
  100. #define T_ASSIGN    '='    /* operators: */
  101. #define T_MUL        '*'
  102. #define T_DIV        '/'
  103. #define T_MOD        '%'
  104. #define T_ADD        '+'
  105. #define T_SUB        '-'
  106. #define T_SHL        'L'
  107. #define T_SHR        'R'
  108. #define T_LT        '<'
  109. #define T_LE        'l'
  110. #define T_GT        '>'
  111. #define T_GE        'g'
  112. #define T_EQ        'q'
  113. #define T_NE        'n'
  114. #define T_NOT        '~'
  115. #define T_AND        '&'
  116. #define T_XOR        '^'
  117. #define T_IOR        '|'
  118. #define T_LNOT        '!'
  119. #define T_LAND        'a'
  120. #define T_LIOR        'o'
  121. #define T_INCR        'p'
  122. #define T_DECR        'm'
  123. #define T_IF        'i'    /* keywords: */
  124. #define T_ELSE        'e'
  125. #define T_WHILE        'w'
  126. #define T_BREAK        'b'
  127. #define T_CHAR        'c'
  128. #define T_INT        't'
  129. #define T_BEGIN        'B'
  130. #define T_END        'E'
  131. #define T_NF        'f'
  132. #define T_NR        '#'
  133. #define T_FS        ' '
  134. #define T_RS        '\n'
  135. #define T_FILENAME    'z'
  136.  
  137. #define PATTERN    'P'    /* indicates C statement is within a pattern */
  138. #define ACTION    'A'    /* indicates C statement is within an action */
  139.  
  140. /*
  141.  * Symbol Table values
  142.  */
  143. #define ACTUAL        0
  144. #define LVALUE        1
  145. #define BYTE        1
  146. #define WORD        2
  147. /*
  148.  * Symbol table
  149.  */
  150. struct variable {
  151.     char    vname[ MAXVARLEN ];
  152.     char    vclass;
  153.     char    vsize;
  154.     int    vlen;
  155.     char    *vptr;
  156. };
  157. #define VARIABLE struct variable
  158. EXTERN VARIABLE Vartab[ MAXVARTABSZ ], *Nextvar;
  159. /*
  160.  * Value stack
  161.  */
  162. union datum {
  163.     int    ival;
  164.     char     *dptr;
  165.     char    **ptrptr;
  166. };
  167. #define DATUM union datum
  168. struct item {
  169.     char    class;
  170.     char    lvalue;
  171.     char    size;
  172.     DATUM    value;
  173. };
  174. #define ITEM struct item
  175. EXTERN ITEM Stackbtm[ MAXSTACKSZ ], *Stackptr, *Stacktop;
  176. /*
  177.  * Miscellaneous
  178.  */
  179. EXTERN char *Actptr;    /* pointer into Workbuf during compilation */
  180. EXTERN char Token;    /* current input token */
  181. EXTERN DATUM Value;    /* and its value */
  182. EXTERN char Saw_break;    /* set when break stmt seen */
  183. EXTERN char Where;    /* indicates whether C stmt is a PATTERN or ACTION */
  184. EXTERN char Fieldsep[3];    /* field seperator */
  185. EXTERN char Recordsep[3];    /* record seperator */
  186. EXTERN char *Beginact;    /* BEGINning of input actions */
  187. EXTERN char *Endact;    /* END of input actions */
  188.  
  189. /**********************************************************
  190.  * Rules structure                                        *
  191.  **********************************************************/
  192. struct rule {
  193.     struct {
  194.         char *start;    /* C statements that match pattern start */
  195.         char *stop;    /* C statements that match pattern end */
  196.         char startseen;    /* set if both a start and stop pattern */
  197.                 /* given and if an input line matched the */
  198.                 /* start pattern */
  199.     } pattern;
  200.     char *action;        /* contains quasi-C statements of actions */
  201.     struct rule *nextrule;    /* pointer to next rule */
  202. };
  203. #define RULE struct rule
  204. EXTERN RULE *Rules,        /* rule structures linked list head */
  205.     *Rulep;            /* working pointer */
  206.  
  207.  
  208. /**********************************************************
  209.  * Miscellaneous                                          *
  210.  **********************************************************/
  211. /*
  212.  * Error exit values (returned to command shell)
  213.  */
  214. #define USAGE_ERROR    1    /* error in invokation */
  215. #define FILE_ERROR    2    /* file not found errors */
  216. #define RE_ERROR    3    /* bad regular expression */
  217. #define ACT_ERROR    4    /* bad C action stmt */
  218. #define MEM_ERROR    5    /* out of memory errors */
  219. /*
  220.  * Functions that return something special:
  221.  */
  222. char *str_compile(), *getmem(), *cclass(), *pmatch(), *fetchptr();
  223. VARIABLE *findvar(), *addvar(), *decl();
  224.